home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / labyrunr.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  4KB  |  155 lines

  1. #include "driver.h"
  2. #include "vidhrdw/konamiic.h"
  3. #include "vidhrdw/generic.h"
  4.  
  5. unsigned char *labyrunr_videoram1,*labyrunr_videoram2;
  6. static struct tilemap *layer0, *layer1;
  7.  
  8.  
  9. void labyrunr_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  10. {
  11.     int i,pal;
  12.  
  13.     for (pal = 0;pal < 8;pal++)
  14.     {
  15.         if (pal & 1)    /* chars, no lookup table */
  16.         {
  17.             for (i = 0;i < 256;i++)
  18.                 *(colortable++) = 16 * pal + (i & 0x0f);
  19.         }
  20.         else    /* sprites */
  21.         {
  22.             for (i = 0;i < 256;i++)
  23.                 if (color_prom[i] == 0)
  24.                     *(colortable++) = 0;
  25.                 else
  26.                     *(colortable++) = 16 * pal + color_prom[i];
  27.         }
  28.     }
  29. }
  30.  
  31.  
  32. /***************************************************************************
  33.  
  34.   Callbacks for the TileMap code
  35.  
  36. ***************************************************************************/
  37.  
  38. static void get_tile_info0(int tile_index)
  39. {
  40.     int attr = labyrunr_videoram1[tile_index];
  41.     int code = labyrunr_videoram1[tile_index + 0x400];
  42.     int bit0 = (K007121_ctrlram[0][0x05] >> 0) & 0x03;
  43.     int bit1 = (K007121_ctrlram[0][0x05] >> 2) & 0x03;
  44.     int bit2 = (K007121_ctrlram[0][0x05] >> 4) & 0x03;
  45.     int bit3 = (K007121_ctrlram[0][0x05] >> 6) & 0x03;
  46.     int bank = ((attr & 0x80) >> 7) |
  47.             ((attr >> (bit0+2)) & 0x02) |
  48.             ((attr >> (bit1+1)) & 0x04) |
  49.             ((attr >> (bit2  )) & 0x08) |
  50.             ((attr >> (bit3-1)) & 0x10) |
  51.             ((K007121_ctrlram[0][0x03] & 0x01) << 5);
  52.     int mask = (K007121_ctrlram[0][0x04] & 0xf0) >> 4;
  53.  
  54.     bank = (bank & ~(mask << 1)) | ((K007121_ctrlram[0][0x04] & mask) << 1);
  55.  
  56.     SET_TILE_INFO(0,code+bank*256,((K007121_ctrlram[0][6]&0x30)*2+16)+(attr&7))
  57. }
  58.  
  59. static void get_tile_info1(int tile_index)
  60. {
  61.     int attr = labyrunr_videoram2[tile_index];
  62.     int code = labyrunr_videoram2[tile_index + 0x400];
  63.     int bit0 = (K007121_ctrlram[0][0x05] >> 0) & 0x03;
  64.     int bit1 = (K007121_ctrlram[0][0x05] >> 2) & 0x03;
  65.     int bit2 = (K007121_ctrlram[0][0x05] >> 4) & 0x03;
  66.     int bit3 = (K007121_ctrlram[0][0x05] >> 6) & 0x03;
  67.     int bank = ((attr & 0x80) >> 7) |
  68.             ((attr >> (bit0+2)) & 0x02) |
  69.             ((attr >> (bit1+1)) & 0x04) |
  70.             ((attr >> (bit2  )) & 0x08) |
  71.             ((attr >> (bit3-1)) & 0x10) |
  72.             ((K007121_ctrlram[0][0x03] & 0x01) << 5);
  73.     int mask = (K007121_ctrlram[0][0x04] & 0xf0) >> 4;
  74.  
  75.     bank = (bank & ~(mask << 1)) | ((K007121_ctrlram[0][0x04] & mask) << 1);
  76.  
  77.     SET_TILE_INFO(0,code+bank*256,((K007121_ctrlram[0][6]&0x30)*2+16)+(attr&7))
  78. }
  79.  
  80.  
  81. /***************************************************************************
  82.  
  83.     Start the video hardware emulation.
  84.  
  85. ***************************************************************************/
  86.  
  87. int labyrunr_vh_start(void)
  88. {
  89.     layer0 = tilemap_create(get_tile_info0,tilemap_scan_rows,TILEMAP_OPAQUE,8,8,32,32);
  90.     layer1 = tilemap_create(get_tile_info1,tilemap_scan_rows,TILEMAP_OPAQUE,8,8,32,32);
  91.  
  92.     if (layer0 && layer1)
  93.     {
  94.         struct rectangle clip = Machine->drv->visible_area;
  95.         clip.min_x += 40;
  96.         tilemap_set_clip(layer0,&clip);
  97.  
  98.         clip.max_x = 39;
  99.         clip.min_x = 0;
  100.         tilemap_set_clip(layer1,&clip);
  101.  
  102.         return 0;
  103.     }
  104.     return 1;
  105. }
  106.  
  107.  
  108.  
  109. /***************************************************************************
  110.  
  111.   Memory Handlers
  112.  
  113. ***************************************************************************/
  114.  
  115. WRITE_HANDLER( labyrunr_vram1_w )
  116. {
  117.     if (labyrunr_videoram1[offset] != data)
  118.     {
  119.         labyrunr_videoram1[offset] = data;
  120.         tilemap_mark_tile_dirty(layer0,offset & 0x3ff);
  121.     }
  122. }
  123.  
  124. WRITE_HANDLER( labyrunr_vram2_w )
  125. {
  126.     if (labyrunr_videoram2[offset] != data)
  127.     {
  128.         labyrunr_videoram2[offset] = data;
  129.         tilemap_mark_tile_dirty(layer1,offset & 0x3ff);
  130.     }
  131. }
  132.  
  133.  
  134.  
  135. /***************************************************************************
  136.  
  137.   Screen Refresh
  138.  
  139. ***************************************************************************/
  140.  
  141. void labyrunr_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  142. {
  143.     tilemap_set_scrollx(layer0,0,K007121_ctrlram[0][0x00] - 40);
  144.     tilemap_set_scrolly(layer0,0,K007121_ctrlram[0][0x02]);
  145.  
  146.     tilemap_update(ALL_TILEMAPS);
  147.     if (palette_recalc())
  148.         tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
  149.     tilemap_render(ALL_TILEMAPS);
  150.  
  151.     tilemap_draw(bitmap,layer0,0);
  152.     K007121_sprites_draw(0,bitmap,spriteram,(K007121_ctrlram[0][6]&0x30)*2,40,0,-1);
  153.     tilemap_draw(bitmap,layer1,0 );
  154. }
  155.